package com.augurit.wf.app.document.utils;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

//import com.augurit.astat.formula.web.logic.form.ReportTableForm;

public class FileUtils {
	public static void saveHtml(String html, String prePath) {
		saveStringToFile(html, prePath);
	}

//	public static ReportTableForm getReportById(Long id, String prePath) {
//		ReportTableForm form = new ReportTableForm();
//		form.setReportId(id);
//		String html = getStringFromFile(prePath);
//		form.setHtml(html);
//		return form;
//	}

	public static String getStringFromFile(String path) {
		String content = "";
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					new FileInputStream(path), "utf-8"));
			String line = "";
			while ((line = br.readLine()) != null) {
				content += line + "\r\n";
			}
			br.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return content;
	}

	public static void saveStringToFile(String content, String path) {
		System.out.println("jsp文件保存路径：" + path);
		try {
			BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
					new FileOutputStream(path), "UTF-8"));
			writer.write(content);
			writer.flush();
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		System.out.println("保存成功");
	}

}
